<ui:composition template="/WEB-INF/templates/main-template.xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

	<ui:define name="sidebar">
		<ui:include src="/WEB-INF/templates/public-sidebar.xhtml" />
	</ui:define>
	<ui:define name="content">
		<h:form id="viewLeavesForm">
			
            <h:outputText value="Employee Leaves" styleClass="outputTextTitle" style="margin-left:2px;"/>
			<h:panelGrid columns="3"  columnClasses="gridCellMiddleLeftAligned, gridCellMiddleRightAligned">
				
					<h:outputLabel value="Select" />
			         <h:outputLabel value=":" />		
					 <p:menuButton value="#{viewLeavesBean.selectedButton}">
					 <p:menuitem value="Leaves To Be Approved" actionListener="#{viewLeavesBean.buttonChangeListner}" update="@form"></p:menuitem>
					 <p:menuitem value="Leaves To Be Cancelled" actionListener="#{viewLeavesBean.buttonChangeListner}" update="@form"></p:menuitem> 
					
					</p:menuButton>
					
		   </h:panelGrid>

			<h:panelGrid id="searchResultPanel" style="width: 100%; " rendered="#{viewLeavesBean.LEAVES_FOUND}">
				<h:outputLabel value="Leaves requested" styleClass="outputTextSubTitle"/>
				<p:dataTable id="leavesToBeApprovedTable" var="employeeLeave"  paginatorPosition="bottom" rows="10"  paginator="true" 
                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                 rowsPerPageTemplate="5,10,15" value="#{viewLeavesBean.employeeLeavesToApproved}">
	
					<p:column headerText="Employee Code">
						<h:outputText value="#{employeeLeave.employee.employeeCode}" />
					</p:column>
	                <p:column>
							<f:facet name="header">
								<h:outputText value="Leave Type" />
							</f:facet>
							<h:outputText value="#{employeeLeave.leaveType.leaveType}" />
						</p:column>  
					<p:column headerText="Employee Name">
						<h:outputText value="#{employeeLeave.employee.firstName} #{employeeLeave.employee.lastName}" />
					</p:column>
	              
					
					
					   <p:column>
							<f:facet name="header">
								<h:outputText value="Leave From" />
							</f:facet>
							<h:outputText value="#{employeeLeave.periodFrom}" >
							<f:convertDateTime pattern="dd-MMM-yyyy" timeZone="#{viewLeavesBean.defaultTimeZone}"></f:convertDateTime>
							</h:outputText>
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Leave To" />
							</f:facet>
							<h:outputText value="#{employeeLeave.periodTo}" >
							 <f:convertDateTime pattern="dd-MMM-yyyy" timeZone="#{viewLeavesBean.defaultTimeZone}"/>
							</h:outputText>
						</p:column>
					
					<p:column headerText="Status" >
						<h:outputText value="#{employeeLeave.approvalStatus}" style="color:green;font-style:bold;" rendered="#{employeeLeave.approvalStatus eq 'APPROVED'}"/>
						<h:outputText value="#{employeeLeave.approvalStatus}" style="color:#FFCCO;font-style:bold;" rendered="#{employeeLeave.approvalStatus eq 'IN PROCESS'}"/>
						<h:outputText value="#{employeeLeave.approvalStatus}" style="color:#F60000;" rendered="#{employeeLeave.approvalStatus eq 'REJECTED'}"/>
						<h:outputText value="#{employeeLeave.approvalStatus}" style="color:#F60000;" rendered="#{employeeLeave.approvalStatus eq 'CANCELLED'}"/>
					</p:column>
					
					<p:column headerText="Approve">
						<p:commandButton id="selectButton" oncomplete="dialog.show()" update=":viewLeavesForm:dialog"  value="Approve" disabled="#{employeeLeave.approvalStatus eq 'APPROVED' or employeeLeave.approvalStatus eq 'REJECTED' or employeeLeave.approvalStatus eq 'CANCELLED'}">    
		                	  <f:setPropertyActionListener target="#{viewLeavesBean.selectedEmployeeLeave}" value="#{employeeLeave}"></f:setPropertyActionListener>
		                </p:commandButton> 
					</p:column>
				</p:dataTable>
			</h:panelGrid>
			
			<h:panelGrid rendered="#{viewLeavesBean.LEAVES_NOT_FOUND}">
			 <h:outputLabel value="No leaves to be approved" style="color:red;font-size:16px;"/>
			</h:panelGrid>
			
			<h:panelGrid id="searchResult" style="width: 100%; " rendered="#{viewLeavesBean.LEAVES_TO_BE_CANCELLED_FOUND}">
				<h:outputLabel value="Leaves requested for cancellation" styleClass="outputTextSubTitle"/>
				<p:dataTable id="leavesToBeCancelledTable" var="employeeLeave" value="#{viewLeavesBean.employeeLeavesToCancelled}" paginatorPosition="bottom" rows="10"  paginator="true" 
                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                 rowsPerPageTemplate="5,10,15" >
	
					<p:column headerText="Employee Code">
						<h:outputText value="#{employeeLeave.employee.employeeCode}" />
					</p:column>
	                <p:column>
							<f:facet name="header">
								<h:outputText value="Leave Type" />
							</f:facet>
							<h:outputText value="#{employeeLeave.leaveType.leaveType}" />
					</p:column>
					<p:column headerText="Employee Name">
						<h:outputText value="#{employeeLeave.employee.firstName} #{employeeLeave.employee.lastName}" />
					</p:column>
	
					
					
					   <p:column>
							<f:facet name="header">
								<h:outputText value="Leave From" />
							</f:facet>
							<h:outputText value="#{employeeLeave.periodFrom}" >
							<f:convertDateTime pattern="dd-MMM-yyyy" timeZone="#{viewLeavesBean.defaultTimeZone}"></f:convertDateTime>
							</h:outputText>
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Leave To" />
							</f:facet>
							<h:outputText value="#{employeeLeave.periodTo}" >
							 <f:convertDateTime pattern="dd-MMM-yyyy" timeZone="#{viewLeavesBean.defaultTimeZone}"/>
							</h:outputText>
						</p:column>
					<p:column headerText="Status">
					    <h:outputText value="#{employeeLeave.approvalStatus}" style="color:#FFCCO;font-style:bold;" rendered="#{employeeLeave.approvalStatus eq 'CANCELLATION IN PROCESS'}"/>
						<h:outputText value="#{employeeLeave.approvalStatus}" style="color:#F60000;" rendered="#{employeeLeave.approvalStatus eq 'CANCELLED'}"/>
						<h:outputText value="#{employeeLeave.approvalStatus}" style="color:#F60000;" rendered="#{employeeLeave.approvalStatus eq 'REJECTED'}"/>
					</p:column>
					
					
					<p:column headerText="Approve">
					    
						<p:commandButton id="selectButton" oncomplete="dialogToCancel.show()" update=":viewLeavesForm:dialogToCancel"  value="Approve" disabled="#{employeeLeave.approvalStatus eq 'CANCELLED' or employeeLeave.approvalStatus eq 'REJECTED'}">  
		                	  <f:setPropertyActionListener target="#{viewLeavesBean.selectedEmployeeLeave}" value="#{employeeLeave}"></f:setPropertyActionListener>
		                </p:commandButton> 
					</p:column>
				</p:dataTable>
				
				
			</h:panelGrid>
			<h:panelGrid rendered="#{viewLeavesBean.LEAVES_TO_BE_CANCELLED_NOT_FOUND}">
			      <h:outputLabel value="No leave requests to be cancelled" style="color:red;font-size:16px;"/>
			 </h:panelGrid>
			
			
			<p:dialog header="#{viewLeavesBean.selectedEmployeeLeave.employee.firstName} #{viewLeavesBean.selectedEmployeeLeave.employee.lastName}'s Leave Details to Approve/Reject" id="dialog" widgetVar="dialog"  resizable="false" modal="true">
				<h:panelGrid id="leavesDetailsPanel" style="">
					
				<h:panelGrid columns="6" style="border: 1px solid #d9d9d9;width: 800px" cellspacing="10" columnClasses="grid148pxCellMiddleLeftAligned, gridCellMiddleLeftAligned, grid168pxCellMiddleLeftAligned, grid148pxCellMiddleLeftAligned, gridCellMiddleLeftAligned, grid168pxCellMiddleLeftAligned">
				  <h:outputLabel value="#{msg['employeeidoremployeename.label']}" style="font-size: 12px;" />
					<h:outputLabel value=" : " />				
					<p:inplace>  
	                       <p:inputText value="#{viewLeavesBean.selectedEmployeeLeave.employee.firstName}/#{viewLeavesBean.selectedEmployeeLeave.employee.employeeCode}" readonly="true"/>  
	                </p:inplace>
					
					
					<h:outputLabel value="#{msg['modulename.label']}" style="font-size: 12px;" />
					<h:outputLabel value=" : " />				
					<p:inplace>  
	                       <p:inputText value="#{viewLeavesBean.selectedEmployeeLeave.employee.moduleName}" readonly="true"/>  
	                </p:inplace>
	               
	              
	                 <h:outputLabel value="#{msg['projectname.label']}" style="font-size: 12px;" />
					<h:outputLabel value=" : " />				
					<p:inplace>   
					 
	                       <p:inputText value="#{viewLeavesBean.selectedEmployeeLeave.project}" readonly="true"/>
	                        
	                </p:inplace>
	                 
					<h:outputLabel value="#{msg['leavetype.label']}" style="font-size: 12px;" />
					<h:outputLabel value=" : " />				
					<p:inplace>  
	                       <p:inputText value="#{viewLeavesBean.selectedEmployeeLeave.leaveType.leaveType}" readonly="true"/>  
	                </p:inplace>
	               
					<h:outputLabel value="#{msg['leaveappliedon.label']}" style="font-size: 12px;" />
					<h:outputLabel value=" : " />				
					<p:inplace >   
	                       <p:inputText value="#{viewLeavesBean.selectedEmployeeLeave.appliedOn}" readonly="true">
	                        <f:convertDateTime pattern="dd-MMM-yyyy"/>
	                       </p:inputText>  
	                </p:inplace>
	               
	               
	                
	                <h:outputLabel value="#{msg['timetnterval.label']}" style="font-size: 12px;" />
					<h:outputLabel value=" : " />
					<h:panelGroup>				
					<h:panelGrid columns="3">				
					<p:inplace >   
					      
	                       <p:inputText value="#{viewLeavesBean.selectedEmployeeLeave.periodFrom}" readonly="true">
	                        <f:convertDateTime pattern="dd-MMM-yyyy" timeZone="#{viewLeavesBean.defaultTimeZone}"/>  
	                       
	                       </p:inputText> 
                    </p:inplace>
	                <h:outputText value="to"/>
	                	
					      <p:inplace >   
	                       <p:inputText value="#{viewLeavesBean.selectedEmployeeLeave.periodTo}" readonly="true">
	                        <f:convertDateTime pattern="dd-MMM-yyyy" timeZone="#{viewLeavesBean.defaultTimeZone}"/>  
	                       
	                       </p:inputText> 
                            </p:inplace>
	                </h:panelGrid>
	                </h:panelGroup>
	                 <h:outputLabel  value="#{msg['nodays.label']}" style="font-size: 12px;" />
					<h:outputLabel value=" : " />				
					<p:inplace >   
	                       <p:inputText value="#{viewLeavesBean.selectedEmployeeLeave.noOfDays}" readonly="true"/> 
	                       
	                </p:inplace>
	                
	                 <h:outputLabel  value="#{msg['tomail.label']}" style="font-size: 12px;" />
					<h:outputLabel value=" : " />				
					<p:inplace >   
	                       <p:inputText value="#{viewLeavesBean.selectedEmployeeLeave.employee.email}" readonly="true"/> 
	                       
	                </p:inplace>
	              
	                
	                 
	                <h:outputLabel  value="#{msg['availablecontactnumber.lable']}" style="font-size: 12px;" />
					<h:outputLabel value=" : " />				
					<p:inplace >   
	                       <p:inputText value="#{viewLeavesBean.selectedEmployeeLeave.availableContactNumber}" readonly="true"/> 
	                       
	                </p:inplace>
	               <h:outputLabel value="#{msg['availableaddress.label']}" style="font-size: 12px;" />
					<h:outputLabel value=" : " />				
					<p:inplace>  
	                       <p:inputTextarea value="#{viewLeavesBean.selectedEmployeeLeave.availableAddress}" readonly="true"/> 
	                </p:inplace>
	                 <h:outputLabel  value="#{msg['reasonforleave.label']}" style="font-size: 12px;" />
					<h:outputLabel value=" : " />				
					<p:inplace>  
	                       <p:inputTextarea value="#{viewLeavesBean.selectedEmployeeLeave.reason}" readonly="true"/> 
	                </p:inplace>
	               
	                
				    <h:panelGroup>
	                 <h:outputLabel value="*" style="color:red;" />	
					<h:outputLabel value="#{msg['approverscomments.label']}" style="font-size: 12px;" />
					</h:panelGroup>
					<h:outputLabel value=" : " />				
					  
	                        <p:inputTextarea value="#{viewLeavesBean.selectedEmployeeLeave.approvalComments}" rendered="#{viewLeavesBean.leaveApprovedFlag}"/>
	                        <p:inputTextarea value="#{viewLeavesBean.selectedEmployeeLeave.approvalComments}" readonly="true" rendered="#{not viewLeavesBean.leaveApprovedFlag}"/>  
	               <h:inputHidden/>
	               <h:inputHidden/>
	               <h:inputHidden/>
					<h:inputHidden/>
					<h:inputHidden/>
					<h:panelGroup>
	                <p:commandButton  value="Approve" id="Approve" actionListener="#{viewLeavesBean.approveRejectLeaveAction}" update="@form"/> 
					<p:commandButton  value="Reject" id="Reject" actionListener="#{viewLeavesBean.approveRejectLeaveAction}" update="@form"/>
					</h:panelGroup>
				   <h:inputHidden/>   
				   <h:inputHidden/> 
				</h:panelGrid>
					    
					
				</h:panelGrid>
			</p:dialog>
			
			<p:dialog header="#{viewLeavesBean.selectedEmployeeLeave.employee.firstName} #{viewLeavesBean.selectedEmployeeLeave.employee.lastName}'s Leave Details to Approve/Reject" id="dialogToCancel" widgetVar="dialogToCancel"  resizable="false" modal="true">
				<h:panelGrid id="leavesToCancelDetailsPanel" style="">
					
				<h:panelGrid columns="6" style="border: 1px solid #d9d9d9;width: 800px" cellspacing="10" columnClasses="grid148pxCellMiddleLeftAligned, gridCellMiddleLeftAligned, grid168pxCellMiddleLeftAligned, grid148pxCellMiddleLeftAligned, gridCellMiddleLeftAligned, grid168pxCellMiddleLeftAligned">
				  <h:outputLabel value="#{msg['employeeidoremployeename.label']}" style="font-size: 12px;" />
					<h:outputLabel value=" : " />				
					<p:inplace>  
	                       <p:inputText value="#{viewLeavesBean.selectedEmployeeLeave.employee.firstName}/#{viewLeavesBean.selectedEmployeeLeave.employee.employeeCode}." readonly="true"/>  
	                </p:inplace>
					
					
					<h:outputLabel value="#{msg['modulename.label']}" style="font-size: 12px;" />
					<h:outputLabel value=" : " />				
					<p:inplace>  
	                       <p:inputText value="#{viewLeavesBean.selectedEmployeeLeave.employee.moduleName}" readonly="true"/>  
	                </p:inplace>
	                <h:outputLabel value="#{msg['projectname.label']}" style="font-size: 12px;" />
					<h:outputLabel value=" : " />				
					<p:inplace >   
	                       <p:inputText value="#{viewLeavesBean.employeeAndReporting.project}" readonly="true"/>  
	                </p:inplace>
	                
					<h:outputLabel value="#{msg['leavetype.label']}" style="font-size: 12px;" />
					<h:outputLabel value=" : " />				
					<p:inplace>  
	                       <p:inputText value="#{viewLeavesBean.selectedEmployeeLeave.leaveType.leaveType}" readonly="true"/>  
	                </p:inplace>
	               
					<h:outputLabel value="#{msg['leaveappliedon.label']}" style="font-size: 12px;" />
					<h:outputLabel value=" : " />				
					<p:inplace >   
	                       <p:inputText value="#{viewLeavesBean.selectedEmployeeLeave.appliedOn}" readonly="true">
	                        <f:convertDateTime pattern="dd-MMM-yyyy"/>
	                       </p:inputText>  
	                </p:inplace>
	               
	                
	                <h:outputLabel value="#{msg['timetnterval.label']}" style="font-size: 12px;" />
					<h:outputLabel value=" : " />
					<h:panelGroup>				
					<h:panelGrid columns="3">				
					<p:inplace >   
					      
	                       <p:inputText value="#{viewLeavesBean.selectedEmployeeLeave.periodFrom}" readonly="true">
	                        <f:convertDateTime pattern="dd-MMM-yyyy" timeZone="#{viewLeavesBean.defaultTimeZone}"/>  
	                       
	                       </p:inputText> 
                    </p:inplace>
	                <h:outputText value="to"/>
	                	
					      <p:inplace >   
	                       <p:inputText value="#{viewLeavesBean.selectedEmployeeLeave.periodTo}" readonly="true">
	                        <f:convertDateTime pattern="dd-MMM-yyyy" timeZone="#{viewLeavesBean.defaultTimeZone}"/>  
	                       
	                       </p:inputText> 
                            </p:inplace>
	                </h:panelGrid>
	                </h:panelGroup>
	               <h:outputLabel  value="#{msg['nodays.label']}" style="font-size: 12px;" />
					<h:outputLabel value=" : " />				
					<p:inplace >   
	                       <p:inputText value="#{viewLeavesBean.selectedEmployeeLeave.noOfDays}" readonly="true"/> 
	                       
	                </p:inplace>
	                
	              
	                
	                 <h:outputLabel  value="#{msg['tomail.label']}" style="font-size: 12px;" />
					<h:outputLabel value=" : " />				
					<p:inplace >   
	                       <p:inputText value="#{viewLeavesBean.selectedEmployeeLeave.employee.email}" readonly="true"/> 
	                       
	                </p:inplace>
	             
	                <h:outputLabel  value="#{msg['availablecontactnumber.lable']}" style="font-size: 12px;" />
					<h:outputLabel value=" : " />				
					<p:inplace >   
	                       <p:inputText value="#{viewLeavesBean.selectedEmployeeLeave.availableContactNumber}" readonly="true"/> 
	                       
	                </p:inplace>
	               
	                 <h:outputLabel  value="#{msg['reasonforleavecancellation.label']}" style="font-size: 12px;" />
					<h:outputLabel value=" : " />				
			  
	                <p:inputTextarea value="#{viewLeavesBean.selectedEmployeeLeave.reasonForCancel}" readonly="true"/> 
	        
	               
	              
					 <h:panelGroup>
	                 <h:outputLabel value="*" style="color:red;" />
					<h:outputLabel value="Cancellation Comments" style="font-size: 12px;" />
					</h:panelGroup>
					<h:outputLabel value=" : " />				
					
	                <p:inputTextarea value="#{viewLeavesBean.selectedEmployeeLeave.cancellationComments}" />
	                
	                
					
	                
	                <h:inputHidden /><h:inputHidden />
					<h:inputHidden /><h:inputHidden />
					<h:inputHidden /><h:inputHidden />
					<h:inputHidden /><h:inputHidden />
					<h:inputHidden />
					<h:inputHidden />
					<h:inputHidden />
					<h:panelGrid columns="2">
					 <p:commandButton  value="Approve" id="Accept" actionListener="#{viewLeavesBean.leveCancelRequestApprovedORRejectAction}" update="@form" />
					 <p:commandButton  value="Reject" id="RejectCacellation" actionListener="#{viewLeavesBean.leveCancelRequestApprovedORRejectAction}" update="@form" />
					
				    </h:panelGrid>
				    
				    
				</h:panelGrid>
					
				</h:panelGrid>
				<h:outputLabel styleClass="outputTextTitle" style="font-size:12px;" value="Note:Submitting the leave will automatically send email to TomailId address with comments given above."/>
			</p:dialog>
			
			
			<p:growl id="growl"/>
		</h:form>
	</ui:define>
</ui:composition>

